//
//  BSLPhotoCollectionViewCell.m
//  Demo
//
//  Created by RYAN on 15/6/26.
//
//

#import "BSLPhotoCollectionViewCell.h"
#define BSL_LABEL_HEIGHT_PER 0.25

@implementation BSLPhotoCollectionViewCell

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _photoView = [[UIImageView alloc] initWithFrame:self.contentView.frame];
        [self.contentView addSubview:self.photoView];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - BSL_LABEL_HEIGHT_PER*frame.size.height, frame.size.width, BSL_LABEL_HEIGHT_PER*frame.size.height)];
        _timeLabel = label;
        [self.contentView addSubview:self.timeLabel];
        [self.timeLabel setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]];
        [self.timeLabel setTextAlignment:NSTextAlignmentRight];
        [self.timeLabel setTextColor:[UIColor whiteColor]];
        [self.timeLabel setHidden:YES];
        
        _overlayView = [[UIImageView alloc] initWithFrame:self.photoView.frame];
        [self.overlayView setImage:[UIImage imageNamed:@"Overlay"]];
        [self.contentView addSubview:self.overlayView];
        [self.overlayView setHidden:YES];
        
//        self.isCellSelected = NO;
    }
    return self;
}

//- (void)clicked{
//    [self.overlayView setHidden:self.isCellSelected];
//    self.isCellSelected = !self.isCellSelected;
//}

- (void)setStatus:(BOOL)isUserChosen{
    [self.overlayView setHidden:!isUserChosen];
}

- (void)setDataWithAsset:(BSLAsset *)asset{
    [self.timeLabel setHidden:!asset.isVideo];
    
    if (asset.isVideo) {
        
        [self.timeLabel setText:asset.videoDuration];
    }
    
    [self.photoView setImage:asset.thumbnail];
}

@end
